package com.wanxi.util;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.UserDto;
import com.wanxi.model.UserModel;
import com.wanxi.service.UserService;
import redis.clients.jedis.Jedis;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

public class Tool {

    /**
     * 不让别人创建对象
     */
    private Tool() {
    }

    public static int strToInt(String value) {
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            return -1;
        }

    }
    public static String strToBirthday(String value) {
        String str="yyyy-MM-dd";
        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(str);

        try {
            Date date=simpleDateFormat.parse(value);
            return simpleDateFormat.format(date);
        } catch (Exception e) {
            return "1111-01-01";
        }

    }

    public static int strToPage(String value) {
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            return 1;
        }

    }

    public static int strToLimit(String value) {
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            return 10;
        }

    }

    public static void main(String[] args) {
//        UserModel userModel = UserModel.builder().build();
//        System.out.println(userModel);
//        UserModel model = null;
//        System.out.println(model);
//        System.out.println(new BigDecimal("aaa"));
//    new Tool().aa("",new UserService() {
//
//    });
//        System.out.println(new UserDto());
//        Object[] aa={1,"aa",new int[1],new UserDto()};
        String aa = "aa";
        aa = aa + "fdsa";
    }

    public void aa(String name, UserService userService) {
//        String name="aa";
//        System.out.println(name);
//        System.out.println();
//        Timer timer=new Timer();
//        timer.schedule(new TimerTask() {
//            @Override
//            public void run() {
//                System.out.println(1);
//            }
//        },1000);
    }

    public static BigDecimal strToDecimal(String value) {
        try {
            return new BigDecimal(value);
        } catch (Exception e) {
            return new BigDecimal("0");
        }
    }

    public static String getResult(int count, String... keys) {
        Jedis jedis = new Jedis();

        if (count > 0) {
            jedis.del(keys);
            return "success";
        } else {
            return "error";
        }

    }
}
